package com.landary.parameterrplacement.controller;

import com.landary.parameterrplacement.entity.*;
import com.landary.parameterrplacement.service.*;
import com.landary.parameterrplacement.utils.WebServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 刘欣
 * @createTime 2023/7/28 16:32
 * @description
 */
@RestController
@RequestMapping("/paramConvert")
@Slf4j
public class ParamConversionController {
    @Autowired
    private AnalysisUserXmlService analysisUserXmlService;

    @Autowired
    private AnalysisAvicOrgXmlService analysisAvicOrgXmlService;

    @Autowired
    private AnalysisDeptXmlService analysisDeptXmlService;

    @Autowired
    private AnalysisPostXmlService analysisPostXmlService;

    @Autowired
    private WebServiceClient webServiceClient;

    @Autowired
    private UserParamsConversionService userParamsConversionService;

    /**
     * 对组织机构webservice接口xml解析
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/getSubOrgDepartment")
    @ResponseBody
    public List<Dept> getSubDepartment() throws Exception {
        String responseXml = webServiceClient.getDepts("ou=orgs,ou=131601,o=avic");
//        String responseXml = "<respMsg><header><sysName>APP_UUMS</sysName><isSuccess>true</isSuccess><message>操作成功</message></header><document><![CDATA[<depts>" +
//                "<dept><dn>ou=101,ou=orgs,ou=131601,o=avic</dn><ou>101</ou><avicDeptName>科技委办公室</avicDeptName><avicDeptCode>20613</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode></dept>" +
//                "<dept><dn> ou=102,ou=orgs,ou=131601,o=avic </dn><ou>102</ou><avicDeptName>所党委办公室</avicDeptName><avicDeptCode>20613</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>20613</avicParentDeptCode></dept>" +
//                "<dept><dn> ou=103,ou=orgs,ou=131601,o=avic </dn><ou>103</ou><avicDeptName>综合计划部</avicDeptName><avicDeptCode>103</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>20613</avicParentDeptCode></dept>" +
//                "<dept><dn> ou=104,ou=orgs,ou=131601,o=avic </dn><ou>104</ou><avicDeptName>财务部</avicDeptName><avicDeptCode>104</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>20613</avicParentDeptCode></dept>" +
//                "<dept><dn> ou=105,ou=orgs,ou=131601,o=avic </dn><ou>105</ou><avicDeptName>科研管理部</avicDeptName><avicDeptCode>105</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>20613</avicParentDeptCode></dept>" +
//                "<dept><dn> ou=10501,ou=105,ou=orgs,ou=131601,o=avic </dn><ou>10501</ou><avicDeptName>科研管理部型号副总师</avicDeptName><avicDeptCode>10501</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>20613</avicParentDeptCode></dept>" +
//                "<dept><dn> ou=10501,ou=105,ou=orgs,ou=131601,o=avic </dn><ou>10501</ou><avicDeptName>部门机构</avicDeptName><avicDeptCode>0</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode></dept>" +
//                "<dept><dn> ou=10502,ou=105,ou=orgs,ou=131601,o=avic </dn><ou>10502</ou><avicDeptName>科研管理部综合管理办公室</avicDeptName><avicDeptCode>10502</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>20613</avicParentDeptCode></dept></depts>]]></document></respMsg>";

//        String responseXml = "<respMsg><header><sysName>APP_UUMS</sysName><isSuccess>true</isSuccess><message>操作成功</message></header><document><![CDATA[<depts>" +
//                "<dept><dn> ou=214,ou=orgs,ou=131601,o=avic </dn><ou>214</ou><avicDeptName>能力与总体IT部</avicDeptName><avicDeptCode>214</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>部门机构</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>207</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>科研室主体</avicDeptType></dept>" +
//                "<dept><dn> ou=214007,ou=orgs,ou=131601,o=avic </dn><ou>214007</ou><avicDeptName>能力与总体与IT应用室</avicDeptName><avicDeptCode>214007</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>214</avicParentDeptCode><avicParentName>部门机构</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>207</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>科研室主体</avicDeptType></dept>" +
//                "</depts>]]></document></respMsg>";
//        log.info("部门机构webservice返回参数" + responseXml);
//        String responseXmlAvic = "<respMsg>" +
//                " <header>" +
//                " <sysName>APP_UUMS</sysName>" +
//                " <isSuccess>true</isSuccess>" +
//                " <message>操作成功</message>" +
//                " </header>" +
//                " <document>" +
//                " <![CDATA[<depts>" +
//                " <dept><dn> ou=214,ou=orgs,ou=131601,o=avic </dn><ou>214</ou><avicDeptName>能力与总体IT部</avicDeptName><avicDeptCode>214</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>部门机构</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>207</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>科研室主体</avicDeptType></dept>" +
//                " <dept><dn> ou=116,ou=orgs,ou=131601,o=avic </dn><ou>116</ou><avicDeptName>离退休服务中心</avicDeptName><avicDeptCode>116</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>中国航空工业集团公司沈阳飞机设计研究所</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>116</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>职能管理</avicDeptType></dept>" +
//                " <dept><dn> ou=102,ou=orgs,ou=131601,o=avic </dn><ou>102</ou><avicDeptName>所(党委)办公室</avicDeptName><avicDeptCode>102</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>中国航空工业集团公司沈阳飞机设计研究所</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>102</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>职能管理</avicDeptType></dept>" +
//                " <dept><dn> ou=215,ou=orgs,ou=131601,o=avic </dn><ou>215</ou><avicDeptName>装备技术经济中心</avicDeptName><avicDeptCode>215</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>中国航空工业集团公司沈阳飞机设计研究所</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>215</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>科研主体</avicDeptType></dept>" +
//                " <dept><dn> ou=407,ou=orgs,ou=131601,o=avic </dn><ou>407</ou><avicDeptName>辽宁依航企业服务有限公司</avicDeptName><avicDeptCode>407</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>中国航空工业集团公司沈阳飞机设计研究所</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>215</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>副处级</avicDeptRank><avicDeptType>子公司</avicDeptType></dept>" +
//                " <dept><dn> ou=216,ou=orgs,ou=131601,o=avic </dn><ou>216</ou><avicDeptName>科研人才能力中心</avicDeptName><avicDeptCode>216</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>部门机构</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>216</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>科研主体</avicDeptType></dept>" +
//                " <dept><dn> ou=406,ou=orgs,ou=131601,o=avic </dn><ou>406</ou><avicDeptName>沈阳航盛科技有限责任公司</avicDeptName><avicDeptCode>406</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>中国航空工业集团公司沈阳飞机设计研究所</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>406</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>无</avicDeptRank><avicDeptType>子公司</avicDeptType></dept>" +
//                " <dept><dn> ou=409,ou=orgs,ou=131601,o=avic </dn><ou>409</ou><avicDeptName>扬州协同创新研究院有限公司</avicDeptName><avicDeptCode>409</avicDeptCode><avicDeptState>1</avicDeptState><avicParentDeptCode>0</avicParentDeptCode><avicParentName>中国航空工业集团公司沈阳飞机设计研究所</avicParentName><aviceDeptState>1</aviceDeptState><avicSortOrder>406</avicSortOrder><avicDeptLevel>1</avicDeptLevel><avicDeptRank>正处级</avicDeptRank><avicDeptType>科研主体</avicDeptType></dept>" +
//                " </depts>]]>" +
//                " </document>" +
//                "</respMsg>";
        List<Dept> depts = analysisDeptXmlService.xmlToMap(responseXml, "dept");
//        log.info("部门机构参数转换" + depts);
        return depts;
    }


    /**
     * 对组织人员webservice接口xml解析
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/getSubPerson")
    @ResponseBody
    public List<BatchUsers> getSubPerson() throws Exception {
//        String responseXml = "<respMsg><header><sysName>APP_UUMS</sysName><isSuccess>true</isSuccess><message>操作成功</message></header><document><![CDATA[<users>" +
//                "<user><dn>cn=test1, ou=orgs,ou=131601,o=avic </dn><cn>90005008</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>yefuyang@sy601.com</mail><avicUserAccount>yefuyang</avicUserAccount><avicDeptName>综合航电部综合感知技术研究室</avicDeptName><avicSortOrder>1000</avicSortOrder><avicDeptCode>20613</avicDeptCode><avicEmployeeType>挂职借调人员</avicEmployeeType><avicUserSecurity>1</avicUserSecurity><avicLocalCode>900005008</avicLocalCode><fullName>叶富阳</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>" +
//                "<user><dn>cn=test2, ou=orgs,ou=80201,o=avic </dn><cn>90005007</cn><avicCorpCode>80201</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>wailairenyuan@sy601.com</mail><avicUserAccount>wailairenyuan</avicUserAccount><avicDeptName>外来人员</avicDeptName><avicSortOrder>1000</avicSortOrder><avicDeptCode>80201</avicDeptCode><avicEmployeeType>挂职借调人员</avicEmployeeType><avicUserSecurity>1</avicUserSecurity><avicLocalCode>900005008</avicLocalCode><fullName>外来人员</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>" +
//                "</users>]]></document></respMsg>";

//                String responseXml = "<respMsg><header><sysName>APP_UUMS</sysName><isSuccess>true</isSuccess><message>操作成功</message></header><document><![CDATA[<users>" +
//                "<user><dn>cn=18200415, ou=21400,ou=214,ou=214,o=avic </dn><cn>18200415</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>renyuan1@sy601.com</mail><avicUserAccount>renyuan1</avicUserAccount><avicDeptName>能力与总体与IT部办公室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21400</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>人员1</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>"+
//                        "<user><dn>cn=18200415, ou=21400,ou=214,ou=214,o=avic </dn><cn>18200414</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>renyuan2@sy601.com</mail><avicUserAccount>renyuan2</avicUserAccount><avicDeptName>能力与总体与IT部办公室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21400</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>人员2</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>"+
//                        "<user><dn>cn=18200415, ou=21400,ou=214,ou=214,o=avic </dn><cn>18200413</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>renyuan3@sy601.com</mail><avicUserAccount>renyuan3</avicUserAccount><avicDeptName>能力与总体与IT部办公室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21400</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>人员3</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>"+
//                        "<user><dn>cn=18200415, ou=21400,ou=214,ou=214,o=avic </dn><cn>18200412</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>renyuan4@sy601.com</mail><avicUserAccount>renyuan4</avicUserAccount><avicDeptName>能力与总体与IT部办公室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21400</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>人员4</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>"+
//                        "<user><dn>cn=18200415, ou=21400,ou=214,ou=214,o=avic </dn><cn>18200411</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>renyuan5@sy601.com</mail><avicUserAccount>renyuan5</avicUserAccount><avicDeptName>能力与总体与IT部办公室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21400</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>人员5</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>"+
//                "</users>]]></document></respMsg>";

//        String responseXmlAvic = "<respMsg>" +
//                "<header>" +
//                "<sysName>APP_UUMS</sysName>" +
//                "<isSuccess>true</isSuccess>" +
//                "<message>操作成功</message>" +
//                "</header>" +
//                "<document>" +
//                "<![CDATA[<users>" +
//                "<user><dn>cn=18200415, ou=21400,ou=214,ou=214,o=avic </dn><cn>18200415</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>lilan@sy601.com</mail><avicUserAccount>lilan</avicUserAccount><avicDeptName>能力与总体与IT部办公室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21400</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>李兰</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>\"+\n" +
//                "<user><dn>cn=18200415, ou=21407,ou=214,ou=214,o=avic </dn><cn>18200415</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>副室主任</avicSimpleTitle><mail>sunyan@sy601.com</mail><avicUserAccount>sunyan</avicUserAccount><avicDeptName>能力与总体与IT应用室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21407</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>孙岩</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>\"+\n" +
//                "<user><dn>cn=18200415, ou=21407,ou=214,ou=214,o=avic </dn><cn>18200415</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>团委书记</avicSimpleTitle><mail>sunyan@sy601.com</mail><avicUserAccount>ceshiyong</avicUserAccount><avicDeptName>能力与总体与IT应用室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21407</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>测试用户</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>\"+\n" +
//                "<user><dn>cn=18709299, ou=21407,ou=214,ou=214,o=avic </dn><cn>18709299</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>部长</avicSimpleTitle><mail>liuxiaodong1@sy601.com</mail><avicUserAccount>liuxiaodong1</avicUserAccount><avicDeptName>能力与总体与IT部办公室</avicDeptName><avicSortOrder>200</avicSortOrder><avicDeptCode>21400</avicDeptCode><avicEmployeeType>正式职工</avicEmployeeType><avicIdCardNumber>210103198211282117</avicIdCardNumber><avicUserSecurity>2</avicUserSecurity><avicLocalCode>60103441</avicLocalCode><fullName>刘晓冬</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>\"+\n" +
//                "</users>]]>" +
//                "</document>" +
//                "</respMsg>";
        String responseXml = webServiceClient.getUsers("appPORTALLoginEnable", "ou=orgs,ou=131601,o=avic");

//        log.info("组织人员webservice返回参数" + responseXml);
        List<User> users = analysisUserXmlService.userXmlToMap(responseXml, "user");
        List<BatchUsers> batchUsers = getBatchUsers(users);
        return batchUsers;
    }

    /**
     * 集成平台组织架构接入接口限制，调用一次知只能同步1000条数据，进行分页处理
     *
     * @param users
     * @return
     * @throws Exception
     */
    private List<BatchUsers> getBatchUsers(List<User> users) throws Exception {
        int batchSize = 1000; // 每份的大小
        int index = 0;
        List<User> batch = new ArrayList<>();
        Map<Integer, List<User>> userMap = new LinkedHashMap<>();
        for (User user : users) {
            if (batch.size() >= batchSize) {
                userMap.put(index, batch);
                index++;
                batch = new ArrayList<>();
            }
            batch.add(user);
        }
        if (!batch.isEmpty()) {
            userMap.put(index, batch); // 添加最后一份
        }
        int lastIndex = 0;
        if (userMap.size() - 1 >= 0) {
            lastIndex = userMap.size() - 1;
        }


        List<BatchUsers> batchUsers = new ArrayList<>();
        for (Map.Entry<Integer, List<User>> entry : userMap.entrySet()) {
            BatchUsers batchUser = new BatchUsers();
            if (entry.getKey() == lastIndex) {
                batchUser.setFinish(true);
                List<MkOrgUser> mkOrgUsers = new ArrayList<>();
                List<User> mkOrgUser = entry.getValue();
                for (User user : mkOrgUser) {
                    MkOrgUser mkUser = userParamsConversionService.userParamsConversion(user);
                    mkOrgUsers.add(mkUser);
                }
                batchUser.setUsers(mkOrgUsers);
                batchUsers.add(batchUser);
            } else {
                batchUser.setFinish(false);
                List<MkOrgUser> mkOrgUsers = new ArrayList<>();
                List<User> mkOrgUser = entry.getValue();
                for (User user : mkOrgUser) {
                    MkOrgUser mkUser = userParamsConversionService.userParamsConversion(user);
                    mkOrgUsers.add(mkUser);
                }
                batchUser.setUsers(mkOrgUsers);
                batchUsers.add(batchUser);
            }
        }
//        log.info("组织人员参数转换" + users);
//        log.info("分批次同步组织人员" + batchUsers);
        return batchUsers;
    }


    /**
     * 对组织岗位webservice接口xml解析
     *
     * @return
     */
    @RequestMapping("/getSubPost")
    @ResponseBody
    public List<Post> getSubPost() throws Exception {
//        String responseXml = "<respMsg><header><sysName>APP_UUMS</sysName><isSuccess>true</isSuccess><message>操作成功</message></header><document><![CDATA[<users>" +
//                "<user><dn>cn=test1, ou=orgs,ou=131601,o=avic </dn><cn>90005008</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>yefuyang@sy601.com</mail><avicUserAccount>lisi</avicUserAccount><avicDeptName>综合航电部综合感知技术研究室</avicDeptName><avicSortOrder>1000</avicSortOrder><avicDeptCode>20613</avicDeptCode><avicEmployeeType>挂职借调人员</avicEmployeeType><avicUserSecurity>1</avicUserSecurity><avicLocalCode>900005008</avicLocalCode><fullName>叶富阳</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>" +
//                "<user><dn>cn=test2, ou=10502,ou=105,ou=orgs,ou=131601,o=avic </dn><cn>test2</cn></user><user><dn>cn=test1, ou=orgs,ou=131601,o=avic </dn><cn>90005008</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>yefuyang@sy601.com</mail><avicUserAccount>zhangsan</avicUserAccount><avicDeptName>综合航电部综合感知技术研究室</avicDeptName><avicSortOrder>1000</avicSortOrder><avicDeptCode>20613</avicDeptCode><avicEmployeeType>挂职借调人员</avicEmployeeType><avicUserSecurity>1</avicUserSecurity><avicLocalCode>900005008</avicLocalCode><fullName>叶富阳</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user>" +
//                "<user><dn>cn=test1, ou=orgs,ou=131601,o=avic </dn><cn>90005008</cn><avicCorpCode>131601</avicCorpCode><avicSimpleTitle>一般工作人员</avicSimpleTitle><mail>yefuyang@sy601.com</mail><avicUserAccount>yefuyang</avicUserAccount><avicDeptName>综合航电部综合感知技术研究室</avicDeptName><avicSortOrder>1000</avicSortOrder><avicDeptCode>20613</avicDeptCode><avicEmployeeType>挂职借调人员</avicEmployeeType><avicUserSecurity>1</avicUserSecurity><avicLocalCode>900005008</avicLocalCode><fullName>叶富阳</fullName><avicCorpName>航空工业沈阳飞机设计研究所</avicCorpName></user></users>]]></document></respMsg>";
        String responseXml = webServiceClient.getUsers("appPORTALLoginEnable", "ou=orgs,ou=131601,o=avic");
//        log.info("组织人员webservice返回参数" + responseXml);
        List<Post> postList = analysisPostXmlService.xmlToMaP(responseXml, "user");
//        log.info("组织岗位参数转换" + postList);
        return postList;
    }


    /**
     * 对虚拟组织webservice接口xml解析
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/getSubAvicDepartment")
    @ResponseBody
    public List<AvicOrg> getSubAvicDepartment() throws Exception {
        String xmlData = "<![CDATA[" +
                "<avicOrgs>" +
                "<dept>" +
                "<ou>BDA9DC9C4973450595C2CC932BC22610</ou>" +
                "<avicDeptName>测试项目群</avicDeptName>" +
                "<avicParentDeptCode>0</avicParentDeptCode>" +
                "<avicParentDeptName>沈阳飞机设计研究所</avicParentDeptName>" +
                "<avicDeptState>1</avicDeptState>" +
                "<avicShowCode> ceshi</avicShowCode>" +
                "</dept>" +
                "<dept>" +
                "<ou>757E5D90BD944E4E9D497182C70EEBC2</ou>" +
                "<avicDeptName>测试团队1</avicDeptName>" +
                "<avicParentDeptCode> BDA9DC9C4973450595C2CC932BC22610</avicParentDeptCode>" +
                "<avicParentDeptName>测试项目群</avicParentDeptName>" +
                "<avicDeptState>1</avicDeptState>" +
                "<avicShowCode>ceshiT</avicShowCode >" +
                "</dept>" +
                "</avicOrgs>" +
                "]]>";
        log.debug("虚拟组织webservice返回参数" + xmlData);
        List<AvicOrg> avicOrgs = analysisAvicOrgXmlService.xmlToMap(xmlData, "dept");
        return avicOrgs;
    }

}
